<?php
/* $Id$ */
use Buan\Config;
use Buan\UrlCommand;
use Buan\View;
$urlRoot = Config::get('ext.Scribble.urlRoot');

View::getGlobalView()->addStylesheets("{$urlRoot}/css/scribble/media-library/index.css");
View::getGlobalView()->addJavascripts("{$urlRoot}/js/scribble/media-library/index.js");
if(isset($_GET['popup'])) {
	View::getGlobalView()->addJavascripts("{$urlRoot}/js/tinymce/tiny_mce_popup.js");
}
?>

<div class="head">
	<h1>Media Library</h1>
	<h2>Files &amp; Folders</h2>
</div>

<table class="list">
	<thead>
		<tr>
			<th class="col-icon">&#160;</th>
			<th class="col-name">Name</th>
			<th class="col-actions">Actions</th>
		</tr>
	</thead>
	<tbody class="folders">
	<?php if($parentFolder!==NULL): ?>
		<tr>
			<td class="col-icon">&#160;</td>
			<td class="col-name"><a href="<?php $this->html->e(UrlCommand::createUrl('scribble', 'media-library', array('f'=>$parentFolder))); ?>">[back to parent]</a></td
			<td></td>
		</tr>
	<?php endif; ?>
	<?php foreach($items->folders as $item): ?>
		<tr>
			<td class="col-icon">&#160;</td>
			<td class="col-name"><a href="<?php $this->html->e(UrlCommand::createUrl('scribble', 'media-library', array('f'=>$item->relativeUrl))); ?>">/<?php $this->html->e(basename($item->relativeUrl)); ?></a></td>
			<td>
				<a href="#" onclick="deleteItem('<?php $this->html->e($item->relativeUrl); ?>', this);return false;">delete</a>
				| <a href="<?php $this->html->eUrl(UrlCommand::createUrl('scribble', 'media-library', 'folder', array('f'=>$item->relativeUrl))); ?>">edit</a>
			</td>
		</tr>
	<?php endforeach; ?>
	</tbody>

	<tbody class="files">
	<?php foreach($items->files as $item): ?>
		<tr>
			<td class="col-icon">&#160;</td>
			<td class="col-name"><a href="<?php $this->html->e($item->absoluteUrl); ?>" onclick="selectFile(this);"><?php $this->html->e(basename($item->relativeUrl)); ?></a></td>
			<td>
				<a href="" onclick="deleteItem('<?php $this->html->e($item->relativeUrl); ?>', this);return false;">delete</a>
			</td>
		</tr>
	<?php endforeach; ?>
	</tbody>
</table>

<script type="text/javascript">
var parentFolder = <?php echo $parentFolder===NULL ? 'null' : "'".$this->html->e($parentFolder, FALSE)."'"; ?>;
var currentFolder = <?php echo $currentFolder===NULL ? 'null' : "'".$this->html->e($currentFolder, FALSE)."'"; ?>;
</script>